package Array;

import org.junit.Test;

import java.util.Arrays;

/**
 * @BelongsProject: SeniorArchitect-LeetCode
 * @BelongsPackage: Array
 * @Author: zhuangxiaoyan
 * @CreateTime: 2023-10-18  16:28
 * @Description: TODO
 * @Version: 1.0
 */
public class 轮转数组189 {
    public void swap(int[] array, int left, int right) {
        while (left < right) {
            int tmp = array[right];
            array[right] = array[left];
            array[left] = tmp;
            right--;
            left++;
        }
    }

    // 这就是一个的一个组数的反转
    public void rotate(int[] nums, int k) {
        int len = nums.length;
        k = k % len;
        swap(nums, 0, len - k - 1);
        swap(nums, len - k, nums.length - 1);
        swap(nums, 0, nums.length - 1);
        System.out.println(Arrays.toString(nums));
    }

    @Test
    public void test() {
        rotate(new int[]{-1, -100, 3, 99}, 2);
    }
}
